#read in newbler dataframes
grouse1hc <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse1HCDiffs.txt')
grouse2hc <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse2HCDiffs.txt')
grouse3hc <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse3HCDiffs.txt')

grouse1All <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse1AllDiffs.txt')
grouse2All <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse2AllDiffs.txt')
grouse3All <- readNewblerMapper('/Paterson/Datafiles/grouse/grouse_seq_cap/grepped/gGrouse3AllDiffs.txt')


hcSNPlist <- vector("list",length(contig.map)) #578 in length
names(hcSNPlist) <- names(contig.map)
hcCoveragelist <- vector("list",length(contig.map))
names(hcCoveragelist) <- names(contig.map)

for(i.ctg in 135:length(contig.map)){ #1:length(contig.map)
	if(identical(contig.map[[i.ctg]],0)) next
	hcSNPlist[[i.ctg]] <- try(captureSNPs(contig.map,c("grouse1hc","grouse2hc","grouse3hc"),names(contig.map[i.ctg]),c("grouse1CO","grouse2CO","grouse3CO"),c("/Paterson/Datafiles/grouse/mapping/grouse1.ace","/Paterson/Datafiles/grouse/mapping/grouse2.ace","/Paterson/Datafiles/grouse/mapping/grouse3.ace")))
	hcCoveragelist[[i.ctg]] <- try(baseCoverage(hcSNPlist[[i.ctg]]))
	if(class(hcCoveragelist[[i.ctg]])=='try-error'){
		cat(i.ctg, " fails.\n")
		}else{
		cat(i.ctg, " works.\n")
		}
	if((i.ctg/10 - floor(i.ctg/10)) == 0) save.image()
	}
save.image(file='wksp_2010_02_04.rdata')

#hcCoveragelist2 <- hcCoveragelist
hcCoveragelist2 <- vector("list",length(contig.map))
names(hcCoveragelist2) <- names(hcCoveragelist)

source('coding_snps3.R')

#for(i.ctg in 1:50){
#	hcCoveragelist2[[i.ctg]] <- try(codingSNPref(hcCoveragelist[[i.ctg]]))
	#names(hcCoveragelist2)[i.ctg] <- names(hcCoveragelist)[i.ctg]
#	}

for(i.ctg in 1:length(hcCoveragelist2)){
	hcCoveragelist2[[i.ctg]] <- try(codingSNPref(hcCoveragelist[[i.ctg]]))
	#names(hcCoveragelist2)[i.ctg] <- names(hcCoveragelist)[i.ctg]
	}
